package org.example.security.bo;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.example.db.entity.Permission;
import org.example.db.entity.User;
import org.example.db.entity.WxUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@NoArgsConstructor
public class SecurityWxUserDetails implements UserDetails {


    private WxUser wxUser;
    private List<Permission> permissionList;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return permissionList.stream()
                .map(permission -> new SimpleGrantedAuthority(permission.getId() + ":" + permission.getName()))
                .collect(Collectors.toList());
    }

    @Override
    public String getPassword() {
        return String.valueOf(wxUser.getId());
    }

    @Override
    public String getUsername() {
        return String.valueOf(wxUser.getId());
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
